package com.huangyuqiang.utils;

import java.util.Arrays;

/**
 * Created by hyq on 2015/12/15.
 */
public abstract class ValueObject {
    protected abstract Object[] getAttributesToCheckEquality();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ValueObject valueObject = (ValueObject) o;

        return Arrays.deepEquals(getAttributesToCheckEquality(), valueObject.getAttributesToCheckEquality());
    }

    @Override
    public int hashCode() {
        int hash = 17;
        for (Object attribute : getAttributesToCheckEquality()) {
            hash = hash * 31 + (attribute == null ? 0 : attribute.hashCode());
        }
        return hash;
    }
}
